<?php
namespace app\shop\model;
use app\BaseModel;
use think\facade\Db;



class IndexShopSpePrice extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_shop_spe_price';

    protected static function init()
    {
        //TODO:初始化内容
    }


    /**
     * @var array
     * 查询器
     */
    protected $append = [
        'spe_array_text',
        'spe_name_text'
    ];
    /**
     * @param $value
     * @param $data
     * @return mixed
     * get spename
     */
    public function getSpeNameTextAttr($value,$data){
        $pec_id   = explode('-',$data['spe_id_1']);
        $spe_name = Db::name('longbing_card_shop_spe')->where('id','IN',$pec_id)->column('title');
        return  implode('-',$spe_name);
    }
    /**
     * @param $value
     * @param $data
     * @return mixed
     * get spearray
     */
    public function getSpeArrayTextAttr($value,$data){
        return explode('-',$data['spe_id_1']);
    }

    /**
     * @param $dis
     * @param int $page
     * @return mixed
     * 获取商品多规格价格库存
     */
    public function goodsSpePrice($dis){
        $data = $this->where($dis)->select()->toArray();
        return $data;
    }

    /**
     * @param $dis
     * @param int $page
     * @return mixed
     * 获取商品多规格价格库存
     */
    public function SpePriceFind($dis){
        $data = $this->where($dis)->find();
        return !empty($data)?$data->toArray():$data;
    }

    /**
     * @param $dis
     * @param $data
     * @return IndexShopSpePrice
     * 编辑规格
     */

    public function spePriceUpdate($dis,$data){
        $data['update_time'] = time();
        $res = $this->where($dis)->update($data);
        return $res;

    }


    /**
     * User: chenniang
     * Date: 2019-09-27 16:04
     * @param $dis
     * @return void
     * descption:获取总库存
     */
    public function spePriceStock($dis){
        $stock = $this->where($dis)->sum('stock');
        return $stock;
    }










}